package org.example.cicdi.service.fieldchain;


import org.example.cicdi.enums.EnumWhiteColumnAnnotation;
import org.example.cicdi.service.impl.ext.AbstactFieldAnnotationServiceExt;
import org.example.codegenerate.modelext.WebVo.domian.column.ColumnVoDomain;
import org.example.codegenerate.modelext.WebVo.domian.table.TableVoDomain;
import org.example.codegenerate.modelext.WebVo.domian.table.WebModelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.OneToMany;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

@Service
public class OneToManyAnnotatonImpleServiceExt extends AbstactFieldAnnotationServiceExt {
	@Autowired
	private FieldChainFacaService fieldChainFacaService;
	@Override
	public String getCode() {
		return EnumWhiteColumnAnnotation.DbVo.getCode();
	}

	@Override
	public void execute(ColumnVoDomain columnVoDomain, Field field, WebModelVo model) {
		if (field.getAnnotation(OneToMany.class) != null) {
			//executeonetoMany(columnVoDomian,field,model);
		}
	}

	private void executeonetoMany(ColumnVoDomain columnVoDomain, Field field, WebModelVo model) throws Exception{
		if (field.getType().equals(List.class)) {
			Type type = field.getGenericType();
			if (type instanceof ParameterizedType) {
				ParameterizedType pt = (ParameterizedType) type;
				// 获取泛型里的class类型对象
				Class<?> fClass = (Class<?>)pt.getActualTypeArguments()[0];
				/*
				TableVoDomain sonTable = sonModel.getTableVoDomain();
				model.getTableVoDomain().getSonTabeleVoDomain().add(sonTable);*/
				TableVoDomain sonTable=new TableVoDomain();
				List<ColumnVoDomain> columnVoDomainList =fieldChainFacaService.handleFieldAnnotations(fClass);
				sonTable.getColumnVoDomainList().addAll(columnVoDomainList);

				System.out.println("fclass:"+fClass.toString());
			}
		}
	}
}



